package cn.itcast.demo.solrcloud;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CloudSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.junit.Test;

import java.io.IOException;

public class SolrJCloudIndexTest {


    @Test
    public void testCloudIndexTest() throws IOException, SolrServerException {

        //solrj要请求zookeeper
        //写zookeeper的地址，目的为使得solrJ可以访问到zookeeper，并可以从zookeeper中获取到注册的solr服务，拿到solr服务后solrJ来请求这些服务
        CloudSolrServer solrServer = new CloudSolrServer("192.168.206.101:2181,192.168.206.102:2181,192.168.206.103:2181");

        solrServer.setDefaultCollection("myCollection1");

        SolrInputDocument document = new SolrInputDocument();

        document.addField("id","112345");
        document.addField("title","最近经济形式一片大好");

        solrServer.add(document);

        solrServer.commit();

    }
}
